package com.ld.admin.controller.usercenter;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ld.admin.controller.AdminBasicController;
import com.ld.admin.model.usercenter.SysUserCalendarModel;
import com.ld.admin.service.usercenter.SysUserCalendarService;
import com.ld.shieldsb.annotation.duplicate.SubmitRequestIntercept;
import com.ld.shieldsb.common.core.model.Result;
import com.ld.shieldsb.common.web.util.Web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * 用户日历
 * 
 * @ClassName SysUserCalendarController
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2019年02月21日 14:32:08
 *
 */
@Api(tags = "用户日历")
@ConditionalOnProperty(prefix = "modules.sc.usercenter", name = "calender.enable", havingValue = "true", matchIfMissing = true)
@Controller(value = "usercenterSysUserCalendarController")
@RequestMapping("${shieldsb.adminPath}/usercenter/calender")
public class SysUserCalendarController extends AdminBasicController<SysUserCalendarModel> {
    @Autowired
    protected SysUserCalendarService sysUserCalendarService;

    @ApiOperation(value = "搜索结果", notes = "")
    @RequestMapping(path = "/search", method = RequestMethod.GET)
    // 返回json格式
    @ResponseBody
    public Object search() {
        Result result = sysUserCalendarService.getCalendarData(request);
        return Web.Response.resultWithData(result);
    }

    @ApiOperation(value = "跳转到添加/修改用户日历", notes = "")
    @RequestMapping(path = "/toAddOrUpdate", method = RequestMethod.GET)
    public String toAddOrUpd() {
        setAttributes();
        long cid = getLong("cid");
        sysUserCalendarService.getOne(request, getModelClass(), "cid", cid);
        return "a/usercenter/calendar/sysusercalendar_update";
    }

    @ApiOperation(value = "添加/修改用户日历", notes = "")
    @RequestMapping(path = "/addOrUpdate", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    @SubmitRequestIntercept(desp = "提交拦截验证")
    public Object addOrUpd(@Valid SysUserCalendarModel model) {
        Result result = sysUserCalendarService.addOrUpdate(model, model.getId() != null);
        return Web.Response.result(result);
    }

    @ApiOperation(value = "删除用户日历", notes = "")
    @RequestMapping(path = "/del", method = RequestMethod.POST)
    // 返回json格式
    @ResponseBody
    public Object del() {
        long oid = getLong("oid");
        long cid = getLong("cid");
        Result result = null;
        if (oid != 0) {
            result = sysUserCalendarService.remove(getModelClass(), oid);
        } else {
            result = sysUserCalendarService.remove(getModelClass(), "cid", cid);
        }
        return Web.Response.result(result);
    }

}